Fannie Mae mortgage data¶
Import cuXfilter¶
[4]:
from cuXfilter import charts
import cuXfilter
from bokeh import palettes
from cuXfilter.layouts import *
from bokeh.tile_providers import get_provider as gp
tile_provider = gp('STAMEN_TONER')
[ ]:
#update data_dir if you have downloaded datasets elsewhere
DATA_DIR = './data'
Download required datasets¶
[2]:
from cuXfilter.sampledata import datasets_check
datasets_check('mortgage', base_dir=DATA_DIR)
Dataset - ./data/146M_predictions_v2.arrow
dataset already downloaded
Define charts¶
[3]:
cux_df = cuXfilter.DataFrame.from_arrow('./data/146M_predictions_v2.arrow')
[8]:
chart0 = charts.bokeh.choropleth(x='zip', y='delinquency_12_prediction', aggregate_fn='mean', geo_color_palette=palettes.Purples9,
geoJSONSource = 'https://raw.githubusercontent.com/rapidsai/cuxfilter/master/javascript/demos/GTC%20demo/src/data/zip3-ms-rhs-lessprops.json',
tile_provider=tile_provider, data_points=1000)
chart2 = charts.bokeh.bar('delinquency_12_prediction',data_points=50)
chart3 = charts.panel_widgets.range_slider('borrower_credit_score',data_points=50)
Add mappings for chart1¶
[9]:
mapper1 = {}
for val in cux_df.data.dti.unique().to_pandas().tolist():
mapper1[int(val)] = 'l_'+str(val)
chart1 = charts.panel_widgets.drop_down('dti', label_map=mapper1)
#also available: panel_widgets.multi_select
Create a dashboard object¶
[10]:
d = cux_df.dashboard([chart0, chart1], layout=feature_and_base, theme=cuXfilter.themes.dark, title="Ajay's Dashboard")
[11]:
#add more charts
d.add_charts([chart2, chart3])
[12]:
#dashboard object
d
[12]:
Starting the dashboard¶
d.show(‘url you want the dashboard to run’) remote dashboard d.app(‘ipaddress:8888’) within the notebook: If you are using jupyter remotely, use this line instead of second, and replace url with current notebook url
[13]:
# preview the dashboard
await d.preview()
Export the queried data into a dataframe¶
[9]:
queried_df = d.export()
no querying done, returning original dataframe